﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NewstorePlateformeDAO;

namespace NewstorePlateformeApp.Models
{
    public class Reception
    {
        private enum activite_reception { Picking, Encasage };

        public static bool LancerTache(int utilisId)
        {
            bool started = false;

            int? activiteId = GetActivite("QUAI");

            if (activiteId != null)
                started = C_activites_utilisateur.Insert(utilisId, (int)activiteId);

            return started;
        }

        public static bool CreerMouvement(int utilisId, string code, string emplacement)
        {
            int? idMarchandise = MARCHANDISE_CATALOGUE.GetId(code);
            int? idLieu = Lieux.GetId(emplacement);
            if (idMarchandise == 0 || idLieu == 0)
                return false;

            Marchandise marchandise = new Marchandise()
            {
                idMARCHANDISE_CATALOGUE = idMarchandise,
                idLieux = (int)idLieu
            };

            return Marchandise.Insert(utilisId, GetActivite(emplacement), marchandise);
        }

        private static int? GetActivite(string codeLieu)
        {
            if (codeLieu == Constantes.ACTIVITE_PICKING)
            {
                return Activites.GetId(Constantes.ACTIVITE_PICKING);
            }
            else if (codeLieu == Constantes.ACTIVITE_ENCASAGE)
            {
                return Activites.GetId(Constantes.ACTIVITE_ENCASAGE);
            }

            return null;
        }
    }
}